package com.leyou.item.controller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.sevice.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("spec")
public class SpecController {

    @Autowired
    private SpecService specService;

    /**
     * 基于分类id查询规格组列表
     * @param id 分类id
     * @return
     */
    @GetMapping("groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecGroup(@RequestParam("id") Long id){
        return ResponseEntity.ok(specService.querySpecGroup(id));
    }
    /**
     * 查询规格参数列表功能
     * gid:规格组id
     */
    @GetMapping("params")
    public ResponseEntity<List<SpecParamDTO>> querySpecParam(
            @RequestParam(value = "gid",required = false) Long gid,
            @RequestParam(value = "cid",required = false) Long cid,
            @RequestParam(value = "searching",required = false) Boolean searching
            ){
        return ResponseEntity.ok(specService.querySpecParam(gid,cid,searching));
    }

    /**
     * 根据分类查询规格组列表
     */
    @GetMapping("querySpecGroupByCid/{cid}")
    public ResponseEntity<List<SpecGroupDTO>> querySpecGroupByCid(@PathVariable("cid") Long cid){
        return ResponseEntity.ok(specService.querySpecGroupByCid(cid));
    }
}
